<template>  
    <div>  
        <h1>Login页面</h1>  
        <el-button @click="send">跳转</el-button>  
        <!-- <router-link to="/Code">跳转到Code页面</router-link>   -->
    </div>  
</template>  
  
<script>  
export default {  
    name: 'Login',  
    components: {},  
    methods: {  
        send() {  
            this.$router.push('/routeGuardExercise/Code'); // 确保这里的路径是正确的  
        }  
    },  
beforeRouteEnter(to,from,next){
console.log('进入Login页面');
next();
},

    beforeRouteLeave(to, from, next) {  
        // 正确的路径比较  
        if (to.path === '/routeGuardExercise/Code') {  
            console.log('成功导航到/Code');  
            next(); // 允许导航  
        } else {  
            console.log('阻止导航到其他路径');  
            next(false); // 阻止导航  
        }  
    }  
}  
</script>  
  
<style scoped>  
/* 样式代码 */  
</style>